package com.bbc.core.exception;

import cn.hutool.core.util.StrUtil;
import com.bbc.core.constants.CoreConstants;
import com.bbc.core.model.IResponse;

public class BaseException extends RuntimeException {
   private static final long serialVersionUID = 1095433538316185017L;
   private String module;
   private String code;
   private Object[] args;
   private String defaultMessage;
   protected IResponse response;

   public BaseException(Throwable throwable, String messageTemplate, Object... params) {
      super(StrUtil.format(messageTemplate, params), throwable);
      this.code = CoreConstants.FAIL.toString();
   }

   public BaseException(String module, String code, Object[] args, String defaultMessage) {
      this.code = CoreConstants.FAIL.toString();
      this.module = module;
      this.code = code;
      this.args = args;
      this.defaultMessage = defaultMessage;
   }

   public BaseException(String module, String code, Object[] args) {
      this((String)module, (String)code, (Object[])args, (String)null);
   }

   public BaseException(String module, String defaultMessage) {
      this((String)module, (String)null, (Object[])null, (String)defaultMessage);
   }

   public BaseException(String code, Object[] args) {
      this((String)null, (String)code, (Object[])args, (String)null);
   }

   public BaseException(String msg, Throwable throwable) {
      super(msg, throwable);
      this.code = CoreConstants.FAIL.toString();
   }

   public BaseException(Throwable throwable) {
      super(throwable.getMessage(), throwable);
      this.code = CoreConstants.FAIL.toString();
   }

   public BaseException(String defaultMessage) {
      this((String)null, (String)null, (Object[])null, (String)defaultMessage);
   }

   public String getModule() {
      return this.module;
   }

   public String getCode() {
      return this.code;
   }

   public Object[] getArgs() {
      return this.args;
   }

   public String getDefaultMessage() {
      return this.defaultMessage;
   }

   public void setModule(String module) {
      this.module = module;
   }

   public void setCode(String code) {
      this.code = code;
   }

   public void setArgs(Object[] args) {
      this.args = args;
   }

   public void setDefaultMessage(String defaultMessage) {
      this.defaultMessage = defaultMessage;
   }

   public IResponse getResponse() {
      return this.response;
   }

   public void setResponse(IResponse response) {
      this.response = response;
   }

   public BaseException(IResponse response) {
      super(response.getMessage());
      this.code = CoreConstants.FAIL.toString();
      this.response = response;
   }

   public BaseException(final int code, final String msg) {
      super(msg);
      this.code = CoreConstants.FAIL.toString();
      this.response = new IResponse() {
         public int getCode() {
            return code;
         }

         public String getMessage() {
            return msg;
         }
      };
   }

   public BaseException(IResponse response, Object[] args, String message) {
      super(message);
      this.code = CoreConstants.FAIL.toString();
      this.response = response;
      this.args = args;
   }

   public BaseException(IResponse response, Object[] args, String message, Throwable cause) {
      super(message, cause);
      this.code = CoreConstants.FAIL.toString();
      this.response = response;
      this.args = args;
   }
}
